package com.kedou.net;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.kedou.app.Config;
import com.kedou.app.R;
import com.kedou.net.PostLogin.FailCallback;
import com.kedou.net.PostLogin.SuccessCallback;
import com.kedou.util.Util;

/**
 * 后端请求：取消关注项目
 * 
 * @author zhouchao
 * 
 */
public class PostUnFollowProject {
	public PostUnFollowProject(String token, String projectId, String userId,
			String os, String deviceId, final SuccessCallback successCallback,
			final FailCallback failCallback, final Context context) {
		new NetConnection(
				Util.getSDBaseUrl() + Config.URL_UNFOLLOWPROJECT,
				HttpMethod.POST,
				new NetConnection.SuccessCallback() {

					@Override
					public void onSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							switch (obj.getInt(Config.KEY_STATUSCODE)) {
							case Config.RESULT_STATUS_SUCCESS:
								if (successCallback != null) {
									successCallback.onSuccess(obj
											.getString(Config.KEY_STATUSMSG));
								}
								break;
							default:
								if (failCallback != null) {
									failCallback.onFail(obj
											.getString(Config.KEY_STATUSMSG));
								}
								break;
							}

						} catch (JSONException e) {
							e.printStackTrace();
							if (failCallback != null) {
								failCallback.onFail(context.getResources()
										.getString(R.string.server_have_wrong));
							}
						}
					}
				}, new NetConnection.FailCallback() {

					@Override
					public void onFail() {
						if (failCallback != null) {
							failCallback.onFail(context.getResources()
									.getString(R.string.server_have_wrong));
						}
					}
				}, Config.KEY_TOKEN, token, Config.KEY_PROJECTID, projectId,
				Config.KEY_USERID, userId, Config.KEY_OS, os,
				Config.KEY_DEVICE, deviceId);
	}

	public static interface SuccessCallback {
		void onSuccess(String msg);
	}

	public static interface FailCallback {
		void onFail(String msg);
	}
}
